package com.yunxi.controller.account;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yunxi.account.pojo.AccountGroupVO;
import com.yunxi.account.service.AccountGroupDubboService;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 帐户组 前端控制器
 * </p>
 *
 * @author
 * @since 2019-05-17
 */
@RestController
@RequestMapping("/admin/account/accountGroup")
@Api(tags = "account:accountGroup", description = "帐户组接口")
public class AccountGroupController {
   private static final Logger logger = LoggerFactory.getLogger(AccountGroupController.class);

   //   @Reference(version = "${demo.service.version}",
//           application = "${dubbo.application.id}",
//           url = "${dubbo.application.url}",
//           check = false,
//           timeout = 10000)
   @Autowired
   AccountGroupDubboService accountGroupDubboService;

   @GetMapping("/page")
   @ApiOperation(value = "查询分页")
   public ApiResult page(AccountGroupVO accountGroupVO, Integer pageNum, Integer pageSize) throws Exception {
      return ResponseUtil.ok(accountGroupDubboService.findPageByVO(accountGroupVO, pageNum, pageSize));
   }

   @GetMapping("/list")
   @ApiOperation(value = "查询列表")
   public ApiResult page(AccountGroupVO accountGroupVO) throws Exception {
      return ResponseUtil.ok(accountGroupDubboService.listByVo(accountGroupVO));
   }

   @GetMapping("/load")
   @ApiOperation(value = "读取单个")
   public ApiResult load(String id, @CurrentUser LoginInfo loginInfo) throws Exception {
      return ResponseUtil.ok(accountGroupDubboService.getById(id));
   }

   @PostMapping("/save")
   @ApiOperation(value = "保存信息")
   public ApiResult save(@RequestBody AccountGroupVO accountGroupVO, @CurrentUser LoginInfo loginInfo) throws Exception {
      accountGroupDubboService.saveOrUpdate(accountGroupVO,loginInfo);
      return ResponseUtil.ok("success");
   }

   @PostMapping("/del")
   @ApiOperation(value = "删除")
   public ApiResult del(@RequestBody List<AccountGroupVO> accountGroupVOList,@CurrentUser LoginInfo loginInfo) throws Exception {
      accountGroupDubboService.removeByListVo(accountGroupVOList,loginInfo);
      return ResponseUtil.ok("success");
   }

   @GetMapping("/loadDetail")
   @ApiOperation(value = "读取账户组属性")
   public ApiResult loadDetail(String accountGroupCode) {
      return ResponseUtil.ok(accountGroupDubboService.load(accountGroupCode));
   }

/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(accountGroupService.findMapByList(params));
}*/
}
